from fastapi.encoders import jsonable_encoder

from app.repositories import user_repository
from task.base_info import generate_token
from app.utils.response_util import ResponseUtil

def phone_login(phone: str, code: str):
    # ...登录逻辑...
    user_data = user_repository.get_user_by_phone(phone)
    
    # 返回前确保数据可序列化
    return ResponseUtil.success({
        "user": jsonable_encoder(user_data),  # ← 关键修复点
        "token": generate_token(user_data)
    }) 